package expressions.slogo;

import parsing.Token;
import expressions.IContext;
import expressions.Prefix;

/**
 * Evaluates one of two possible child expressions, based on the value of a
 * condition.
 */
@Token(regex = "if")
public class If extends Prefix<Double>
{
    public If()
    {
        super(2);
    }

    @Override
    public Double evaluate(IContext<Double> context)
    {
        double condition = children.get(0).evaluate(context);

        if (BooleanConstant.toBoolean(condition))
        {
            children.get(1).evaluate(context);
        }

        return condition;
    }

}
